<template>
  <div class="topay">
    <nav-bar :left-arrow="true" :title='title'></nav-bar>
    <div class="contain">
      <div class="card" v-if="isShow">
        <div class="left">
          <img src="../../assets/car.png" alt="">
        </div>
        <div class="right">
          <p>{{pay.type}}</p>
          <span>{{pay.licensePlate}}</span>
          <div class="price">
            <i>{{pay.time}}</i>
          </div>
        </div>
        <div class="btn">
          <van-button type='info' size="small" @click="toPay">立即支付</van-button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import NavBar from '@/components/NavBar'
import { getUnpay, getCarById } from '@/api/car'
import { mapGetters } from 'vuex'

export default {
  name: 'ToPay',
  components: {
    NavBar
  },
  data () {
    return {
      title: '待支付',
      pay: {},
      carId: 0,
      money: 0,
      isShow: false
    }
  },
  computed: {
    ...mapGetters([
      'isLogin',
      'userInfo'
    ])
  },
  created () {
    this.getPayList()
  },
  methods: {
    async getPayList () {
      const params = {
        userId: this.userInfo.userId
      }
      const { data: res } = await getUnpay(params)
      if (res.data !== null) {
        this.carId = res.data.carId
        this.money = res.data.money
        this.getCar()
      }
      console.log(res.data)
    },
    async getCar () {
      // console.log(this.carId)
      const { data: res } = await getCarById(this.carId)
      console.log(res)
      this.isShow = true
      this.pay = res.data
      console.log(this.pay)
      this.startPrice = this.pay.startPrice
    },
    toPay () {
      this.$router.push({
        path: '/pay',
        query: {
          carId: this.carId
        }
      })
    }
  }
}
</script>

<style scoped lang='scss'>
.card{
  display: flex;
  width: 90%;
  margin: 20px 5%;
  border-radius: 5px;
  background-color: rgb(224, 252, 247);
  .right{
    // margin-left: 10px;
    min-width: 178px;
  }
  p{
    font-size: 18px;
    color: rgb(128, 125, 125);
    font-weight: bold;
    margin: 10px 0;
  }
  span{
    font-size: 12px;
    color: #ccc;
  }
  .price{
    span{
      font-size: 16px;
    }
    i{
      font-size: 12px;
      color: #ccc;
    }
  }
}
.btn{
  .van-button{
    margin-top: 40%;
    margin-left: -10px;
  }
}
</style>
